# -*- encoding: utf-8 -*-
"""
    批量生成文件.py
    :description: 
    :date: 2024/07/17 13:05:43
    :version      :1.0
    :copyright: (c) 2024 by enjoyZHou
"""


import datetime
import os
import random

# 定义日期范围
start_date = datetime.datetime(2024, 1, 1)
end_date = datetime.datetime(2024, 7, 17)

# 计算日期差
delta = end_date - start_date

# 指定文件存储的目录
directory = "test_data"


def a():

    # 检查目录是否存在，如果不存在则创建
    if not os.path.exists(directory):
        os.makedirs(directory)

    # 生成文件名
    for i in range(delta.days + 1):
        # 计算当前日期
        current_date = start_date + datetime.timedelta(days=i)
        year = current_date.year
        month = current_date.month
        day = current_date.day

        # 生成一个40到59之间的随机数
        random_number = random.randint(40, 59)

        # 构造文件名
        filename = f"DB_DMDB_FULL_{year}_{month:02d}_{day:02d}_2_00_{random_number}"

        # 构造完整的文件路径
        file_path = os.path.join(directory, filename)

        # 创建空文件
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write('')  # 写入空字符串，创建空文件

        print(f"文件 {filename} 已创建在目录 {directory} 中。")


def get_first_day_of_month(year, month):
    return datetime.datetime(year, month, 1)


def b():

    # 将起始日期设置为该月的第一天
    current_date = get_first_day_of_month(start_date.year, start_date.month)

    while current_date <= end_date:
        print(current_date.strftime('%Y-%m-%d'))

        year = current_date.year
        month = current_date.month
        day = current_date.day

        # 生成一个40到59之间的随机数
        random_number = random.randint(30, 59)

        # 构造文件名
        filename = f"DB_DMDB_FULL_{year}_{month:02d}_{day:02d}_3_00_{random_number}"

        # 构造完整的文件路径
        file_path = os.path.join(directory, filename)

        # 创建空文件
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write('')  # 写入空字符串，创建空文件

        print(f"文件 {filename} 已创建在目录 {directory} 中。")

        current_date = get_first_day_of_month(
            current_date.year, current_date.month + 1)


if __name__ == '__main__':
    b()
